﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Configuration;

namespace FilesUpload
{
    public partial class FormSettings : Form
    {
        public FormSettings()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            string webAddress = this.txtWebAddress.Text.Trim();
            if (string.IsNullOrEmpty(webAddress))
            {
                MessageBox.Show("网站地址不能为空!");
                return;
            }
            else
            {
                System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                AppSettingsSection appSettings = config.AppSettings;
                appSettings.Settings.Remove("WebAddress");
                appSettings.Settings.Add("WebAddress", webAddress);
                config.Save(ConfigurationSaveMode.Modified);
                ConfigurationManager.RefreshSection("appSettings");
                MessageBox.Show("设置成功！");
                this.Close();
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormSettings_Load(object sender, EventArgs e)
        {
            this.txtWebAddress.Text = ConfigurationManager.AppSettings["WebAddress"];
        }
    }
}
